package qihe.dao;



import org.hibernate.Query;

import org.hibernate.transform.Transformers;

import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import qihe.entity.qiheEntity;

import java.util.List;
@Component()
public class qiheDao  extends HibernateDaoSupport {
    public List<qiheEntity> queryPage(String name) {

        String sql = "select * from j06qihe where name like ? ";
        Query query=getSessionFactory().openSession().createSQLQuery(sql);
        query.setParameter(0,  "%" + name + "%");
        //将查询结果转成Map对象的集合
        // query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        query.setResultTransformer(Transformers.aliasToBean(qiheEntity.class));
        List<qiheEntity> list=  query.list();

        return  list;
    }
    @Transactional
    public void save(qiheEntity qihEntity) {
        getSessionFactory().openSession().saveOrUpdate(qihEntity);
    }
}
